
function Menu(){
  var _this=this;
  _this.getTabsDivIndex=0;// 内容初始下标
  
  
  var focusflag=0; 
  
  var tabsDivIndex=0;//上部分div初始下标
  
  

  var tabsDivIndex1=0;//下部分div初始下标
  var $tabsCheck=$("#middleDiv");
  var $topDiv=$("#topDiv");
  var offset=0;
  //初始化整个菜单组件
  var initComponent=function(){
	//  changeTabsDivStatus();
	  keyControl1();
  }

  var keyControl1 = function(){
	  var maxtop=$(".common",$topDiv).length;
	  if(focusflag==0)
		 {
		$(".common",$topDiv).eq(tabsDivIndex).show();
		
		
	  	for(var i=0;i<=maxtop;i++){
	  		if(i!=tabsDivIndex){
	  			$(".common",$topDiv).eq(i).hide();
	  			
	  		}
	  	  }
	  	
		gamel(tabsDivIndex);

  		}
	  }

  
  //改变子菜单选中状态
  var changeTabsDivStatus=function(){
	  var maxtop=$(".common",$tabsCheck).length;
	  
	  _this.getTabsDivIndex=tabsDivIndex1;
	  if(focusflag==1)
		 {
		  
			$(".common",$tabsCheck).eq(tabsDivIndex1).show();
		  	for(var i=0;i<=maxtop;i++){
		  		if(i!=tabsDivIndex1){
		  			$(".common",$tabsCheck).eq(i).hide();
		  			
		  		}
		  	  }
		 
		 }
  }
  
  /**
   * 右移动
   */
  var changeTabsDivRight=function(){
	
	  
	  focusflag=1;
	  changeTabsDivStatus();

		  
	  
}
	
	  
  /**
   * 左移动
   */
  var changeTabsDivLeft=function() {
	  
	  focusflag=0;
	  keyControl1();
//	   $('#d2').animate({
//		   scrollLeft:100
//       }, 100);
//	   
	 //  $("#middleDiv").hide();
	//   $(".img2",$tabsCheck).eq(1).attr("style","border:4px solid #C6E2FF;border-radius:5px;width:100%").focus;
//	   $(".img2").hide();
//	   $(".img2",$("#middleDiv")).eq(1).attr("style","border:4px solid #C6E2FF;border-radius:5px;width:100%").focus;

	 

  }
  /**
   * 下移
   */
  var changeTabsDivDown=function() {
		var maxtop=$(".common",$topDiv).length;
		
		var maxtop1=$(".common",$tabsCheck).length;

		


		if(focusflag==0)
			{
			 if(tabsDivIndex<maxtop)
		  		{
		  			tabsDivIndex++;
			  		keyControl1();

		  		}
			}
			 else
			{
				 if(tabsDivIndex1<maxtop1)
				 {
				 tabsDivIndex1++;
				 changeTabsDivStatus();
				 }

			}
 
  }
  /**
   * 上移
   */
  var changeTabsDivUp=function() {
		if(focusflag==0)
			{
			 if(tabsDivIndex>0)
		  		{
		  			tabsDivIndex--;
			  		keyControl1();

		  		}
			}
			 else
			{
				 if(tabsDivIndex1>0)
				 {
				 tabsDivIndex1--;
				 changeTabsDivStatus();
				 }

			}

  }
  _this.tabsDivTo=function(num){
	  tabsDivIndex1=num;
	  changeTabsDivStatus();
  }
  //右
  _this.tabsDivNext=function(){
	  changeTabsDivRight();
  }
  //左
  _this.tabsDivLast=function(){
	  changeTabsDivLeft();
  }
  //上
  _this.tabsDivUp=function(){
	  changeTabsDivUp();
  }
  //下
  _this.tabsDivDown=function(){
	  changeTabsDivDown();
  }
  //确定
  _this.ok=function(){
  }
  //返回
  _this.cancel=function(){
  }
  
  initComponent();//初始化菜单组件
}
//按键事件数组
var keyEventArray=[
     {
		method:{up:"menu.tabsDivUp()",down:"menu.tabsDivDown()",left:"menu.tabsDivLast()",right:"menu.tabsDivNext()",ok:"menu.ok()",cancel:"menu.cancel()"} //内容控制
	 }
];
function GetQueryString(name){
 	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
 	if(r!=null)return  unescape(r[2]); return null;
 }
var url = "index.html"; //获取传到本页面的参数


var url = GetQueryString("returnUrl"); //获取传到本页面的参数

url="index.html"

var keyboard = function(){   //首页键位设置
    try
    {
        Webview.requestFocus();
        Webview.setKeyEventHandler(function (action, keyCode, keyName, metaState)
        {
			if(keyCode == 92)keyName ="PAGEUP";
			else if(keyCode == 93)keyName ="PAGEDOWN"; 
			switch(keyName){
				case mylib.KEY_LEFT://左
				eval(keyEventArray[0].method.left);
				break;
				case mylib.KEY_UP://上
				eval(keyEventArray[0].method.up);
				break;
				case mylib.KEY_RIGHT://右
				eval(keyEventArray[0].method.right);
				break;
				case mylib.KEY_DOWN://下
			    eval(keyEventArray[0].method.down);
				break;
				case mylib.KEY_SELECT://确认键
				eval(keyEventArray[0].method.ok);
				break;
				case mylib.KEY_BACK:
				Webview.stopVideo();
				if(url!=null){
				window.location.href=url;
				}else {
				Webview.closeBrwoser("返回");
				}
	            break;
			}
        });
    }
    catch (e)
    {
        //监听按键
        document.onkeydown = function (event)
        {
            mylib.KEY_UP = 38;
            mylib.KEY_DOWN = 40;
            mylib.KEY_LEFT = 37;
            mylib.KEY_RIGHT = 39;
            mylib.KEY_SELECT = 13;
			mylib.KEY_PAGEUP = 33;
			mylib.KEY_PAGEDOWN = 34;
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e)
            {
            switch(e.keyCode){
				case 37://左
				eval(keyEventArray[0].method.left);
				break;
				case 38://上
				eval(keyEventArray[0].method.up);
				break;
				case 39://右
				eval(keyEventArray[0].method.right);
				break;
				case 40://下
			    eval(keyEventArray[0].method.down);
				break;
				case 13://确认键
				eval(keyEventArray[0].method.ok);
				break;
				case 8://返回
				window.history.go(-1);
				break;
			   }
            }

        };
    }
}
var autoPlayVideo = function(){  //自动播放
	$.ajax({
		type:"get",
		url:"http://10.255.0.110/mgtv_hndx/MAPindex/GetMediaAssetsItemList?" +
		"BussId=1000000" +
		"&NetId=6953245123" +
		"&UserId=" +mylib.user_id+
		"&IncludeCategory=0" +          
		"&OutputType=json" +
		"&Version=" +mylib.app_version+
		"&CategoryId=1000015" +
		"&PageSize=999" +
		"&MacId=" +mylib.device_mac+
		"&UserAgent=nn_player%2Fstd%2F1.0.0" +
		"&Mac="  +mylib.device_mac+
		"&PageIndex=0" +
		"&MediaAssetsId=Gaming" +
		"&Tag=26&Output_type=jsonp&SortType=time",				
		dataType : "jsonp",
    	jsonp : "nns_jsonp_func",
    	success : function (res)
    	{
	   		var iID = res.item[1].video_id;
	    	$(".el").attr("id",iID); //设置视频框的id
   	 			$.ajax({
				type:"get",
				url:"http://10.255.0.74/nn_cms/nn_cms_view/mgtv_hndx/n3_a_a.php?" +
				"nns_output_type=jsonp&nns_func=get_video_info_v2&nns_video_id="
				 + iID + "&nns_video_type=0&nns_page_index=0&nns_tag=26&nns_page_size=999&nns_version="
		 		+ mylib.app_version,
		 		dataType : "jsonp",
    			jsonp : "nns_jsonp_func",
    			success : function (res)
    				{
           				Webview.stopVideo();
						Webview.setVideoWindowPosition(356,149,556,310);
						var video_id = res.id;
						var video_name=res.name;
						var index_count = res.index_count;
						var index_current = res.index_current; 
						var video_index=res.index_list.index[0].index;
						var media_asset_id = "";
						var playParams = {
       						video_type:"0",//视频类型 0:点播 1:直播    
       						video_id:video_id,//视频ID
        					video_name:video_name,//视频或者频道名称
        					media_asset_id:media_asset_id,//媒资ID
        					category_id:"",//种类ID	
        					ui_style:"0",//展示样式    
        					video_index:video_index,//分集索引号（要播放的集数）
        					quality:"hd",//清晰度
        					video_all_index:index_count,//总集数
        					video_new_index:index_current//更新的集数
   		 			};
    			Webview.playVideo(playParams);
   		 		},
    			error : function (res)
   					{
						callback(res);
   		 			}
				});
   		 },
    	error : function (res)
   		{
			callback(res);
   		 }
		});
}
var autoPlayVideo1 = function(){  //自动播放
	$.ajax({
		type:"get",
		url:"http://10.255.0.110/mgtv_hndx/MAPindex/GetMediaAssetsItemList?" +
		"BussId=1000000" +
		"&NetId=6953245123" +
		"&UserId=" +mylib.user_id+
		"&IncludeCategory=0" +          
		"&OutputType=json" +
		"&Version=" +mylib.app_version+
		"&CategoryId=1000018" +
		"&PageSize=999" +
		"&MacId=" +mylib.device_mac+
		"&UserAgent=nn_player%2Fstd%2F1.0.0" +
		"&Mac="  +mylib.device_mac+
		"&PageIndex=0" +
		"&MediaAssetsId=Gaming" +
		"&Tag=26&Output_type=jsonp&SortType=time",				
		dataType : "jsonp",
    	jsonp : "nns_jsonp_func",
    	success : function (res)
    	{
            var iID1 = res.item[27].video_id;
            $(".ee").attr("id",iID1); //设置视频框的id2值
   	 			$.ajax({
				type:"get",
				url:"http://10.255.0.74/nn_cms/nn_cms_view/mgtv_hndx/n3_a_a.php?" +
				"nns_output_type=jsonp&nns_func=get_video_info_v2&nns_video_id="
				 + iID + "&nns_video_type=0&nns_page_index=0&nns_tag=26&nns_page_size=999&nns_version="
		 		+ mylib.app_version,
		 		dataType : "jsonp",
    			jsonp : "nns_jsonp_func",
    			success : function (res)
    				{
           				Webview.stopVideo();
						Webview.setVideoWindowPosition(356,149,556,310);
						var video_id = res.id;
						var video_name=res.name;
						var index_count = res.index_count;
						var index_current = res.index_current; 
						var video_index=res.index_list.index[0].index;
						var media_asset_id = "";
						var playParams = {
       						video_type:"0",//视频类型 0:点播 1:直播    
       						video_id:video_id,//视频ID
        					video_name:video_name,//视频或者频道名称
        					media_asset_id:media_asset_id,//媒资ID
        					category_id:"",//种类ID	
        					ui_style:"0",//展示样式    
        					video_index:video_index,//分集索引号（要播放的集数）
        					quality:"hd",//清晰度
        					video_all_index:index_count,//总集数
        					video_new_index:index_current//更新的集数
   		 			};
    			Webview.playVideo(playParams);
   		 		},
    			error : function (res)
   					{
						callback(res);
   		 			}
				});
   		 },
    	error : function (res)
   		{
			callback(res);
   		 }
		});
}
var fullScreenPlay = function(){   //全屏播放
	var ul = $("#s").find("img")[0].id; //获取视频框的id
	 	$.ajax({
	 		type:"get",
	 		url:"http://10.255.0.74/nn_cms/nn_cms_view/mgtv_hndx/n3_a_a.php?" +
	 		"nns_output_type=jsonp&nns_func=get_video_info_v2&nns_video_id="
	 		+ ul + "&nns_video_type=0&nns_page_index=0&nns_tag=26&nns_page_size=999&nns_version="
	 		+ mylib.app_version,
	 		dataType : "jsonp",
	 		jsonp : "nns_jsonp_func",
	 		success : function (res)
	 		{
	 			var video_type = 0;
	 			var video_index = res.index_list.index[0].index;	
	 			var video_id = res.id;
	 			 var playIntent = {
                    action : "com.hunantv.operator",//湖南电信、湖南联通
                    extras : {
                        "cmd_ex" : "play_video",
                        "play_video_direct" : 1,
                        "video_id" : video_id,
                        "video_type" : video_type,
                        "video_index" : video_index,
                    },
                    flags : ["SINGLE_TOP"]
                };
                Webview.sendIntent("startActivity", playIntent);//湖南电信、湖南联通
	 		},
	 		error : function (res)
	 		{
	 			callback(res);
	 		}
	 	});
}
var fullScreenPlay1 = function(){   //全屏播放
        var ul = $("#h").find("img")[0].id; //获取视频框的id
        $.ajax({
            type:"get",
            url:"http://10.255.0.74/nn_cms/nn_cms_view/mgtv_hndx/n3_a_a.php?" +
                "nns_output_type=jsonp&nns_func=get_video_info_v2&nns_video_id="
                + ul + "&nns_video_type=0&nns_page_index=0&nns_tag=26&nns_page_size=999&nns_version="
                + mylib.app_version,
            dataType : "jsonp",
            jsonp : "nns_jsonp_func",
            success : function (res)
            {
                var video_type = 0;
                var video_index = res.index_list.index[0].index;
                var video_id = res.id;
                var playIntent = {
                    action : "com.hunantv.operator",//湖南电信、湖南联通
                    extras : {
                        "cmd_ex" : "play_video",
                        "play_video_direct" : 1,
                        "video_id" : video_id,
                        "video_type" : video_type,
                        "video_index" : video_index,
                    },
                    flags : ["SINGLE_TOP"]
                };
                Webview.sendIntent("startActivity", playIntent);//湖南电信、湖南联通
            },
            error : function (res)
            {
                callback(res);
            }
        }); 
}
